package yueyong.salarymanagement.module.business.salary.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import yueyong.salarymanagement.common.anno.NoValidPrivilege;
import yueyong.salarymanagement.common.domain.ResponseDTO;
import yueyong.salarymanagement.constant.SwaggerTagConst;
import yueyong.salarymanagement.module.business.salary.domain.dto.UserCompanySettingDTO;
import yueyong.salarymanagement.module.business.salary.domain.vo.UserCompanyVO;
import yueyong.salarymanagement.module.business.salary.service.UserCompanyService;

import javax.validation.Valid;
import java.util.List;

/**
 * Copyright: yueyong (c) 2022
 *
 * @author he.shaorong
 * @version 1.0
 * @date 2022/2/3
 */
@RestController
@Api(tags = {SwaggerTagConst.Admin.BUSINESS})
public class UserCompanyController {

    @Autowired
    private UserCompanyService userCompanyService;


    @GetMapping("/user/userCompany")
    @ApiOperation(value = "公司信息- 查询用户公司信息", notes = "查询 用户公司信息")
    @NoValidPrivilege
    public ResponseDTO<UserCompanyVO> getUserCompany() {

        List<UserCompanyVO> userCompanyVOList = userCompanyService.queryUserCompany();
        if (userCompanyVOList == null || userCompanyVOList.size() == 0) {
            return ResponseDTO.succ();
        }
        return ResponseDTO.succData(userCompanyVOList.get(0));
    }

    @ApiOperation(value = "公司信息 - 编辑用户公司信息", notes = "设置公司信息")
    @PostMapping("/user/userCompany")
    @NoValidPrivilege
    public ResponseDTO addCompany(@Valid @RequestBody UserCompanySettingDTO userCompanySettingDTO) {
        return userCompanyService.addOrUpdateCompany(userCompanySettingDTO);
    }
}
